import GameConfig from './Data/GameConfig';
/**
 * 玩家每一关过关的信息
 */
export class LevelInfo {
    easy = false;
    middle = false;
    high = false;
}
/**
 * 12星座
 */
export class Constellation {
    /**
     * 摩羯座
     */
    Capricorn = 0;
    /**
     * 水瓶座
     */
    Aquarius = 0;
    /**
     * 双鱼座
     */
    Pisces = 0;
    /**
     * 白羊座
     */
    Aries = 0;
    /**
     * 金牛座
     */
    Taurus = 0;
    /**
     * 双子座
     */
    Gemini = 0;
    /**
     * 巨蟹座
     */
    Cancer = 0;
    /**
     * 狮子座
     */
    Leo = 0;
    /**
     * 处女座
     */
    Virgo = 0;
    /**
     * 天秤座
     */
    Libra = 0;
    /**
     * 天蝎座
     */
    Scorpio = 0;
    /**
     * 射手座
     */
    Sagittarius = 0;
}

export default class StorageCenter{

    /**
     * 获取用户信息
     */
    public static getUserInfo(){
        let info = {
             "name": "游客用户之我自己", 
             "score": StorageCenter.getUserExp(), 
             "head": 7 
        }
        return info;
    }

    /**
     * 体力三连
     */
    public static stamina = null;
    public static getUserStamina(){
        if (StorageCenter.stamina == null){
            let num = ReadLocal('UserStamina',GameConfig.staminaMax);
            let result = CheckNumNaN(num);
            return result;
        }
        else{
            return StorageCenter.stamina;
        }
    }
    public static setUserStamina(num){
        StorageCenter.stamina = num;
        SaveLocal('UserStamina',num);
    }
    public static addUserStamina(num){
        let stamina = StorageCenter.getUserStamina();
        this.setUserStamina(stamina+num);
    }

    /**
     * 经验三连
     */
    public static getUserExp(){
        let num = ReadLocal('UserExp','0');
        let result = CheckNumNaN(num);
        return result;
    }
    public static setUserExp(num){
        SaveLocal('UserExp',num);
    }
    public static addUserExp(num){
        let exp = StorageCenter.getUserExp();
        this.setUserExp(exp+num);
    }

    /**
     * PK胜利三连
     */
    public static getUserVictory(){
        let num = ReadLocal('UserVictory','0');
        let result = CheckNumNaN(num);
        return result;
    }
    public static setUserVictory(num){
        SaveLocal('UserVictory',num);
    }
    public static addUserVictory(num){
        let count = StorageCenter.getUserVictory();
        this.setUserVictory(count+num);
    }

    /**
     * 连续登陆
     */
    public static getUserContinueLogin(){
        let num = ReadLocal('ContinueLogin','0');
        let result = CheckNumNaN(num);
        return result;
    }
    public static setUserContinueLogin(num){
        SaveLocal('ContinueLogin',num);
    }
    public static addUserContinueLogin(){
        let count = StorageCenter.getUserContinueLogin();
        this.setUserContinueLogin(count+1);
    }
    /**
     * 设置玩家闯关信息
     * @param level 第几单元,每一个单元有3关
     * @param small 第几小关,1,2,3对应难度1,2,3
     * @param bookId 当前书本的id
     */
    public static setUserRushLevel(level : number,small : number,bookId:number){
        let info : LevelInfo = new LevelInfo();
        let objson = ReadLocal(`LvInfo_${bookId}_${level}`,JSON.stringify(info));
        let ob = JSON.parse(objson) as LevelInfo;
        switch(small){
            case 1:
                ob.easy = true;
                break;
            case 2:
                ob.middle = true;
                break;
            case 3:
                ob.high = true;
                break;      
        }
        SaveLocal(`LvInfo_${bookId}_${level}`,JSON.stringify(ob));
        return ob;
    }
    /**
     * 获取玩家闯关信息
     * @param level 第几关,每一个part有3关
     * @param bookId 当前书本的id
     */
    public static getUserRushLevel(level : number,bookId:number){
        let info : LevelInfo = new LevelInfo();
        let objson = ReadLocal(`LvInfo_${bookId}_${level}`,JSON.stringify(info));
        let ob = JSON.parse(objson) as LevelInfo;
        return ob;
    }
    /**
     * 获取玩家的星座解锁信息,0为未解锁,1,2,3,4对应4个级别
     */
    public static getUserStar(){
        let info : Constellation = new Constellation();
        let objson = ReadLocal('Constella',JSON.stringify(info));
        let ob = JSON.parse(objson) as Constellation;
        return ob;
    }
    /**
     * 设置玩家的星座信息
     */
    public static setUserStar(info){
        SaveLocal('Constella',JSON.stringify(info));
    }
}
